package sk.stuba.fiit.clientApp.service;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.security.KeyPair;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.PrivateKey;
import java.security.UnrecoverableEntryException;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.security.spec.InvalidKeySpecException;
import java.util.List;

import sk.stuba.fiit.clientApp.cvo.UserDetailCVO;
import sk.stuba.fiit.ltasys.ws.schema.beans.SignatureRequest;

public interface StorageService {

	public static final String ALGORITHM_DSA = "DSA";
	public static final String ALGORITHM_RSA = "RSA";

	public static final String DEFAULT_CERTIFICATE = "c:\\Users\\Administrator\\test\\keystore.jks";
	public static final String DEFAULT_PASSEORD = "password";
	public static final String DEFAULT_STORAGE_TYPE = "jks";

	public void storeXMLSignature(SignatureRequest signature, String outputFile, List<File> fileName) throws IOException;
	
	public List<File> findFileBySignature(String path) throws Exception;
	
	public UserDetailCVO setUserAccount(String name, String password, String id) throws Exception;
	
	public PrivateKey loadPrivateKey(String storageType, String fileName,
			String password) throws KeyStoreException, IOException,
			NoSuchAlgorithmException, CertificateException,
			UnrecoverableKeyException;

	public PrivateKey loadPrivateKeyFromPKCS8(String fileName, String algorithm)
			throws NoSuchAlgorithmException, IOException,
			InvalidKeySpecException;

	public boolean generateAndSaveKeyPair(String path, String algorithm,
			int lenght, String privateKeyName, String publicKeyName)
			throws NoSuchAlgorithmException, NoSuchProviderException;

	public KeyPair generateKeyPair(String algorithm, int lenght)
			throws NoSuchAlgorithmException, NoSuchProviderException;

	public void saveKeyPair(String path, KeyPair keyPair, String namePublicKey,
			String namePrivateKey) throws IOException;

	public void savePrivateKey(String path, PrivateKey key,
			String namePrivateKey) throws IOException;

	public X509Certificate loadCertificateFromCertFile(String fileName)
			throws CertificateException, IOException, InvalidKeySpecException;

	public KeyPair loadKeyPair(String path, String algorithm,
			String publicKeyName, String privateKeyName) throws IOException,
			NoSuchAlgorithmException, InvalidKeySpecException;

	public X509Certificate loadCertificate(String fileName, String password,
			String storageType) throws KeyStoreException,
			NoSuchAlgorithmException, CertificateException,
			FileNotFoundException, IOException, UnrecoverableEntryException;

	public boolean storeCertificate(String storageType, String password,
			X509Certificate certificate, String path, String name);

	public boolean storeCertificateWithPrivateKey(String path, String name,
			PrivateKey key, X509Certificate[] chain, String password);

	public byte[] readFile(File file) throws IOException;

	public void saveBinaryData(File file, byte[] data) throws Exception;

	byte[] loadBinaryData(File file) throws Exception;
}
